<!-- 电子签章模块 -->
<template>
  <el-container class="electronicSignature">
    <el-main class="mainDetails">
      <div>
        <TCollapse title="项目附件信息">
          <div style="margin-bottom: 20px;">  <BtnConfig ref="btnConfigRef" :btn-configs="btnOption" @propClick="btnClick" /></div>
          <MyTable
            id="id"
            ref="myTableRef"
            :table-data="tableData"
            :columns="colOption"
            :col-option-enum="dicLists"
          >
            <template #prjName="{ scope }">
              <el-button type="text" @click="prjNameFun(scope)">{{ scope.prjName }}</el-button>
            </template>
            <template #docName="{ scope }">
              <el-button type="text" @click="goPage(scope)">{{ scope.docName }}</el-button>
            </template>
            <template #signState="{ scope }">
              <el-button type="text" @click="goState(scope)">
                {{ signStateVal(scope) }}
              </el-button>
            </template>
          </MyTable>
          <pagination
            v-if="pageParam.total > 10"
            :total="pageParam.total"
            :page.sync="pageParam.pageNum"
            :limit.sync="pageParam.pageSize"
            @pagination="doSearch"
          />
        </TCollapse>
        <!-- 打开签署状态弹框列表-审批流程 -->
        <el-dialog
          v-if="dialogState"
          v-dialogDrag
          title="审批流程"
          width="50%"
          :append-to-body="true"
          :modal-append-to-body="true"
          :modal="true"
          :close-on-click-modal="false"
          :lock-scroll="true"
          class="pms-dialog"
          :visible.sync="dialogState"
        >
          <div class="dialogForm">
            <SignStatusList ref="signStatusRef" :sign-status-id="signStatusId" />
          </div>
        </el-dialog>
        <!-- 指派签署人-->
        <el-dialog
          v-if="assignPersonDialog"
          ref="dialogUploadRef"
          v-dialogDrag
          :append-to-body="true"
          :modal-append-to-body="true"
          :close-on-click-modal="false"
          :modal="true"
          :title="dialogTitle"
          width="50%"
          class="pms-zr-dialog"
          :visible.sync="dialogUpload"
          @close="() => { isShowStampUnit = false; dialogClosed() }"
        >
          <!-- @touchmove.prevent -->
          <div class="signatoryBody">
            <div v-if="true" class="remark" style="font-size: 13px;color: #eb4b4b;line-height: 22px;">
              <div style="text-indent: -19px;margin-left: 40px;">注:</div>
              <div style="text-indent: -19px;margin-left: 40px;">1、指派签署人仅支持对项目验收单进行操作，项目验收单需单独进行指派签章，与其他文件指派界面为不同界面;</div>
              <div style="text-indent: -19px;margin-left: 40px;">2、项目经理指派签署人时，项目经理默认为签字人，指派的服务商需进行签字盖章；</div>
              <div style="text-indent: -19px;margin-left: 40px;">3、服务商指派签署人时，指派人员为当前文件下一节点的铁塔签字人，与当前流程节点无关，选择指派人时，默认显示项目对应的项目经理；</div>
              <div style="text-indent: -19px;margin-left: 40px;">4、签署人员仅可选择一人，不可多选；</div>
              <div style="text-indent: -19px;margin-left: 40px;">5、在指派提交后，会生成电子签章待办，并在待办中完成签署，不允许重复指派；</div>
              <div style="text-indent: -19px;margin-left: 40px;">6、签章状态默认签署中，待所有用户签署完成后，项目验收单状态更新为签署完成，签署详情可在状态下查看；</div>
            </div>
            <chooseSignatoryTwo
              v-if="isShowStampUnit"
              ref="chooseSignatoryRef"
              class="signatoryClass"
              :query-assign-org="queryAssignOrg"
              @submitPerson="submitPerson"
            />
          </div>
          <div slot="footer" class="pms-zr-dialog-footer">
            <el-button class="pms-zr-button-primary" size="small" :disabled="assignDisable" @click="assignSignatorysubmit">
              提 交
            </el-button>
            <el-button
              class="pms-zr-button-primary pms-zr-ClosedBtn"
              size="small"
              @click="() => { dialogUpload = false; isShowStampUnit = false; dialogClosed() }"
            >
              取 消
            </el-button>
          </div>
        </el-dialog>
        <!-- 选择项目-->
        <el-dialog
          v-if="selectPrj"
          ref="selectPrjDialogRef"
          v-dialogDrag
          :append-to-body="true"
          :modal-append-to-body="true"
          :close-on-click-modal="false"
          :modal="true"
          :title="dialogTitle"
          width="80%"
          class="pms-zr-dialog"
          :visible.sync="selectPrj"
          @close="() => { selectPrj = false; dialogClosed()}"
        >
          <!-- @touchmove.prevent -->
          <div class="signatoryBody">
            <SelectPrjSign
              v-if="isShowSelectPrj"
              ref="selectPrjRef"
              class="signatoryClass"
              @closeSelectWin="() => { isShowStampUnit = false;selectPrj=false;doSearch() ;dialogClosed() }"
            />
          </div>
        </el-dialog>
        <!-- 上传 / 指派签署人 -->
        <el-dialog
          v-if="dialogUploadNew"
          ref="dialogUploadNewRef"
          v-dialogDrag
          :append-to-body="true"
          :modal-append-to-body="true"
          :modal="true"
          :close-on-click-modal="false"
          :title="dialogTitle"
          height="60%"
          width="50%"
          class="pms-dialog"
          :visible.sync="dialogUploadNew"
          @close="() => { isShowStampUnit = false; dialogClosed() }"
        >
          <div class="signatoryBody">
            <UploadAttach
              v-if="isUploadBtn"
              ref="uploadAttachRef"
              :prj-file-type-option="prjFileTypeOption"
              :prj-data="prjData"
              :is-att-info-item-mar="true"
              @changeSignatory="changeSignatory"
            />
            <chooseSignatoryTwo
              v-if="isShowStampUnit"
              ref="chooseSignatoryRef"
              class="signatoryClass"
              :query-assign-org="queryAssignOrg"
              :ass-type="assType"
              @submitPerson="submitPerson"
            />
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button class="pms-zr-button-primary" style="background-color: #eb4b4b; color: #fff;" type="primary" size="small" @click="batchUploadClick">
              提 交
            </el-button>
            <el-button
              class="pms-zr-button-primary pms-zr-ClosedBtn"
              style="background-color: #eb4b4b; color: #fff;"
              size="small"
              @click="() => { isShowStampUnit = false; dialogUploadNew = false; assignUserId = ''; }"
            >
              取 消
            </el-button>
          </div>
        </el-dialog>
      </div>
    </el-main>
  </el-container>
</template>

<script>
// import HeaderTitle from '@/components/basic/HeaderTitle'
import MyTable from '@/components/basic/myTable'
import chooseSignatoryTwo from '@/components/attachmentInfo/chooseSignatoryTwo'
import SelectPrjSign from '../attachSignInfoSelect/attachSignInfoSelect'
import SysConst from '@/common/const'
import BtnConfig from '@/components/basic/btnConfig.vue'
import SignStatusList from '@/components/eleSignature/signStatusList.vue'
import { getDropdownData } from '@/api/common' // 字典接口
import { colOption, btnOption } from '.'
import { disableScroll, enableScroll, msgInfoEl, downloadFileFun } from '@/utils' // singleDownload, mulDownload, downloadFileFun
import {
    submitAssignSignatory, // 电子签章指派签署人
    batchDownloadApi, // 批量下载
    signUploadFileWithoutPrj, // 批量上传
    downloadApi,
    getPrjFileTypeApi,
    batchSign,
    writeSignature,
    assignFixedSignatory,
    writeSignatureOld } from '@/api/attachmentInfo'
import UploadAttach from '@/components/attachmentInfo/uploadAttachForOther'

import {
    deleteIndependent,
    queryProjectFile,
    verifyFileKeyApi,
	downloadFileData,
    checkPersonApi // 预览签署中的pdf
} from '@/api/attachManagement/electronicSign/electronicSignature'
import { ENUM_TYPE_STATUS } from '@/views/attachManagement/electronicSignature/setting'
import TCollapse from '@/components/basic/TCollapse.vue'
export default {
    name: 'ElectronicSignature',
    components: {
        MyTable,
        UploadAttach,
        chooseSignatoryTwo,
        BtnConfig,
        SignStatusList,
        SelectPrjSign,
        TCollapse
    },
    inject: ['workDetail'],
    data() {
        return {
            taskId: '',
            flowType: '',
            currentNode: '',
            tableData: [], // 列表数据
            colOption, // 列表表头
            btnOption, // 列表按钮
            fixedCheckOption: colOption, // 固定字段
            dicLists: {}, // 下拉框字典选项集合
            dialogState: false, // 审批流程列表弹框
            signStatusId: '', // 审批流程Id
            assignPersonDialog: false, // 指派签署人
            selectPrj: false, // 选择项目
            isShowStampUnit: false, // 是否展示签署单位
            // isShowUploadSign: true, // 上传界面指派签署人是否展示
            isShowSelectPrj: false, // 是否展示项目选择界面
            isUploadBtn: false, // 是否点击上传按钮
            // 分页信息
            pageParam: {
                pageSize: SysConst.PAGESIZE, // 每页显示val条
                pageNum: SysConst.CURRENT_PAGE, // 当前页
                total: SysConst.TOTAL // 总数
            },
            prjData: {}, // 嵌套数据数据
            queryAssignOrg: {},
            dialogUploadNew: false,
            prjFileTypeOption: [], // 上传文件类型数据选项
            assignDisable: false,
            assignUserId: '',
            currentDocId: '',
            itSignFlag: '',
            accountType: '',
            signType: '',
            organizeNo: '',
            selectRow: {},
            assType: '' // 区分上传中的指派签署（uplaod）和附件信息页面的指派签署
        }
    },
    computed: {
        // 工作项信息
        newWorkDetail() {
            return this.workDetail()
        },
        // workItemId
      queryWorkInfo() {
           return this.$route.query
      }
    },
    created() {
        console.log(this.newWorkDetail)
        this.taskId = this.newWorkDetail?.bizObject.bizSeq
        this.flowType = this.newWorkDetail?.processDefName === ENUM_TYPE_STATUS ? '1' : '0'
        this.currentNode = this.newWorkDetail?.bizObject.nodeCode
        // this.itSignFlag = this.currentNode === 'electronicSeal_102' ? '1' : (this.currentNode === 'electronicSeal_301' ? '2' : '')
        this.itSignFlag = this.currentNode === 'electronicSeal_102' ? '2' : '1'
        if (this.currentNode === 'electronicSeal_102') {
          // 供应商指派项目经理签字
          this.signType = '0'
        }
        this.getDictData()
        this.doSearch()
    },
    mounted() {
      // 项目附件按钮配置，根据当前页面节点展示不同按钮
      const buttonConfig = [
        {
          nodeId: 'electronicSeal_101',
          buttonValues: ['6', '8'],
          name: '采购经理发起签章流程'
        },
        {
          nodeId: 'electronicSeal_102',
          buttonValues: ['2', '3', '5', '6', '8'],
          name: '供应商确认签章'
        },
        {
          nodeId: 'electronicSeal_301',
          buttonValues: ['1', '5', '8'],
          name: '项目经理签字'
        },
        {
          nodeId: 'electronicSeal_103',
          buttonValues: ['1', '5', '7', '6', '8'],
          name: '采购经理补充签字'
        },
        {
          nodeId: 'electronicSeal_104',
          buttonValues: ['8'],
          name: '领导审批'
        },
        {
          nodeId: 'electronicSeal_105',
          buttonValues: ['4', '8'],
          name: '采购经理盖章'
        },
        {
          nodeId: 'electronicSeal_201',
          buttonValues: ['0', '6', '8'],
          name: '采购经理发起签章流程'
        },
        {
          nodeId: 'electronicSeal_204',
          buttonValues: ['8'],
          name: '领导审批'
        },
        {
          nodeId: 'electronicSeal_205',
          buttonValues: ['4', '8'],
          name: '采购经理盖章'
        }
      ]
      if (this.queryWorkInfo?.type === 'done') {
        this.buttonControl(['8'])
      } else {
        let buttonArr = []
        buttonConfig.forEach(item => {
          if (item.nodeId === this.currentNode) {
            buttonArr = item.buttonValues
          }
        })
        this.buttonControl(buttonArr)
      }
    },
    methods: {
        buttonControl(buttonSelectArr) {
          const buttonResult = []
          buttonSelectArr.map(buttonIndex => {
            this.btnOption.map(buttonItem => {
              if (buttonIndex === buttonItem.index) {
                buttonResult.push(buttonItem)
              }
            })
          })
          this.btnOption = buttonResult
        },
        // 查看数据
        doSearch(item) {
          let flagNum = '00'
          let _workItemId = ''
          if (this.currentNode === 'electronicSeal_102') {
            flagNum = '01'
          }
          if (this.currentNode === 'electronicSeal_301') {
            flagNum = '02'
            _workItemId = this.queryWorkInfo?.workItemId
          }
          const params = {
              pageNum: item?.page || SysConst.CURRENT_PAGE,
              pageSize: item?.limit || SysConst.PAGESIZE,
              taskId: this.taskId,
              prjType: this.flowType,
              workItemId: _workItemId,
              flagNum,
              supplementFlag: this.currentNode === 'electronicSeal_103' ? '01' : ''
          }
          queryProjectFile(params).then(res => {
              if (+res.code !== 200) {
                return Promise.reject(res)
              }
              this.tableData = res.data?.records
              this.pageParam.total = res.data?.total || 0
              this.pageParam.pageSize = item?.limit || SysConst.PAGESIZE
              this.pageParam.pageNum = item?.page || SysConst.CURRENT_PAGE
          })
        },
        // 枚举签署状态
        signStateVal(row) {
          let state = row.signState
          if (['electronicSeal_105', 'electronicSeal_205'].includes(this.currentNode) && row.docType !== 'Z15') {
            state = row.batchState
          }
          // 显示检验
          if (!state && state !== 0) {return ''}
          if (state === '-') {return state}
          let propName = '' // 定义返回字段
          const propObj = this.dicLists['SIGN_STATE2']?.find(sign => sign?.dictId === state) || {}
          propName = JSON.stringify(propObj) !== '{}' ? propObj.dictName : ''
          return propName
        },
        // 列表按钮点击事件
        btnClick(fun, row) {
            this[fun](row)
        },
        // 删除
        async delete(row) {
          const idList = []
          row.map(item => {
            idList.push(item.docId)
          })
          const flagNum = this.currentNode === 'electronicSeal_103' ? '03' : ''
          const params = {
            idList,
            prjType: this.flowType,
            flagNum
          }
          const contentBody = window.top.document.body
          this.$confirm(`确认删除所选数据, 是否继续?`, '删除', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              cancelButtonClass: 'pms-zr-button',
              confirmButtonClass: 'pms-zr-button-primary',
              type: 'warning'
          }).then(() => {
              this.deleteData(params, contentBody)
          }).catch(() => {
              enableScroll(contentBody)
              console.log('取消删除了')
          })
          // el-message-box__wrapper
          // 将弹框挂载在最外层
          this.$nextTick(() => {
              const msgBox = document.querySelector('.el-message-box__wrapper')
              contentBody.appendChild(msgBox)
              disableScroll(contentBody)
          })
        },
        // 调用删除接口
        deleteData(params, contentBody) {
            deleteIndependent(params).then(res => {
                if (+res.code !== 200) {
                  return Promise.reject(res)
                }
                this.doSearch()
                this.$refs.myTableRef.clearSelection()
                this.$message.success('删除成功!')
                enableScroll(contentBody)
            })
        },
        // 点击去往E签宝
        goPage(row) {
          this.queryFileData([row], 'view')
        },
        queryFileData(row, type) {
          const selectedRows = []
          row.map(item => {
            const currentFile = {
              fileId: item.docId,
              fileName: item.docName
            }
            selectedRows.push(currentFile)
          })
          const params = {
            fileMap: selectedRows
          }
          downloadFileData(params).then(res => {
            if (type === 'view') {
              const blob = new Blob([res.data], { type: 'application/pdf;charset-UTF-8' })
              const url = window.URL.createObjectURL(blob)
              const types = row[0].docName.substring(row[0].docName.lastIndexOf('.') + 1)
              if (['word', 'docx', 'excel', 'xlsx'].includes(types)) {
                window.open(this.$router.resolve({
                    name: 'FilePreview',
                    query: {
                        type: types,
                        fileSrc: url
                    }
                }).href, '_blank')
                return
              }
              if (['pdf'].includes(types)) {
                window.open(url, '_blank')
                return
              }
              if (['pptx', 'ppt', 'xls', 'doc', 'txt', 'jpg', 'png', 'jpeg'].includes(types)) {
                return msgInfoEl({
                    type: 'info',
                    message: `所选文件不支持预览`
                })
              }
              URL.revokeObjectURL(url) // 释放内存
            }
            if (type === 'download') {
                const fileName = row.length > 1 ? '电子签章文件.zip' : row[0].docName
                downloadFileFun(res, fileName)
            }
          })
        },
        // 点击签署状态
        goState(row) {
            console.log(row, '点击签署状态')
            this.dialogState = true
            this.signStatusId = row.signId.toString()
        },
        // 获取下拉框数据
        async getDictData() {
            const arr = ['IS_NEWBUSINESS', 'PROJ_TYPE', 'SIGN_STATE2', 'BUILD_MODES']
            const promises = arr.map(item => getDropdownData(item))
            const results = await Promise.all(promises)
            arr.forEach((item, i) => {
                this.$set(this.dicLists, item, results[i].data ?? [])
            })
            this.$set(this.dicLists, 'FILE_UPLOAD_MODES', SysConst.UPLOAD_MODES)
        },
        // 将弹框挂载在最外层
        dialogEl(refName) {
            // 将弹框挂载在最外层
            const contentBody = window.top.document.body
            this.$nextTick(() => {
                const dialogModal = document.querySelector('.v-modal')
                contentBody.appendChild(this.$refs[refName].$el)
                contentBody.appendChild(dialogModal)
                disableScroll(contentBody)
            })
        },
        // 关闭弹框
        dialogClosed() {
            const contentBody = window.top.document.body
            enableScroll(contentBody)
        },
        // 盖章
        async stamp(row) {
            if (row.length > 1) {
              return this.$message.info('当前仅支持单条数据操作')
            }
            if (!(row[0].signState === '2' || row[0].signState === '8')) {
              return this.$message.info('该文件仅支持签署状态为签署中/作废中盖章')
            }
            const res = await checkPersonApi({ ids: row.map(item => item.signId.toString()).join() })
            if (!res.success) {
              return this.$message.error(res.message)
            }
            if (res.data?.isOwn === 0) {
                return this.$message.error('当前所选文件仅支持本人上传的文件发起盖章操作')
            }
            if (row[0].signUrl) {
                window.open(row[0].signUrl)
            }
        },
        // 验签
        async visa(row) {
            if (row[0].signState !== '3') {
              return this.$message.info('该文件仅支持签署状态为已签署完成时验签')
            }
            console.log(row.map(item => item.signId.toString()), 'row.map(item => item.signId) ')
            const res = await checkPersonApi({ ids: row.map(item => item.signId.toString()).join() })
            if (!res.success) {
              return this.$message.error(res.message)
            }
            if (res.data?.isInner === 0) {
                return this.$message.error('当前所选文件仅支持本单位人员进行验签操作')
            }
            if (res.data?.isOwn === 0) {
                return this.$message.error('当前所选文件仅支持本人上传的文件发起验签操作')
            }
            verifyFileKeyApi({ id: row[0].signId.toString() }).then(res_ => {
              if (+res_.code !== 200) {
                  return Promise.reject(res_)
                }
                this.$message.success('验签结果正确')
                this.doSearch({
                    page: this.pageParam.pageNum,
                    limit: this.pageParam.pageSize
                })
            })
        },
        // 下载
        async download(row) {
          this.queryFileData(row, 'download')
        },
        // 查看项目信息
        async prjNameFun(val) {
          const url = `${process.env.VUE_APP_JUNNAN_IFRAME_URL}prjQueryAndExport/projectBaseInfo?prjId=${val.prjId}`
          window.open(url, '_blank')
        },
        batchStamp(row) {
          if (row?.length < 1) {
            return msgInfoEl({
                  type: 'error',
                  message: '请选择至少一条数据进行签署'
            })
          }
          const docIds = []
          row.map(item => {
           docIds.push(item.docId)
          })
          const params = {
            taskId: this.taskId,
            docIds
          }
          batchSign(params).then(res => {
            if (+res.code !== 200) {
                return Promise.reject(res)
            }
            window.open(res.data, '_blank')
          })
        },
        // 点击指派签署人按钮
        assign(row) {
            console.log('row', row)
            if (row.length > 1) {
              return msgInfoEl({
                    type: 'error',
                    message: '仅支持选择一条数据进行指派签署人'
              })
            }
            if (!(row[0].signState === '2')) {
              return this.$message.info('该文件仅支持对签署状态为签署中的进行指派签署人')
            }
            // 非自主研发-项目经理指派签署人仅可对项目验收单进行指派
            if ((this.flowType === '1' && row[0].docType !== 'TP01') ||
              (this.flowType === '0' && row[0].docType !== 'TS01')) {
              return msgInfoEl({
                    type: 'error',
                    message: '非自主研发类项目仅可针对验收单进行指派签署人'
              })
            }
            this.queryAssignOrg = {
              docId: row[0].docId,
              prjId: row[0].prjId,
              nodeId: this.currentNode
            }
            this.currentDocId = row[0].docId
            this.dialogTitle = '指派签署人'
            this.isUploadBtn = false
            this.dialogUpload = true
            this.isShowStampUnit = true
            this.assignPersonDialog = true
            this.assType = 'assignPerson'
        },
        // 指派签署人接口
        assignSignatorysubmit() {
          this.accountType = this.selectRow?.orgType === 's' ? '2' : '1'
          this.organizeNo = this.selectRow?.orgCode
          const params = {
              docId: this.currentDocId,
              itSignFlag: this.itSignFlag,
              signers: [
                {
                  accountType: this.accountType,
                  uniqueId: this.assignUserId,
                  signType: this.signType,
                  organizeNo: this.organizeNo
                }
              ]
          }
          this.assignDisable = true
          submitAssignSignatory(params).then(res => {
              if (+res.code !== 200) {
                  return Promise.reject(res)
              }
              this.dialogUpload = false
              this.doSearch()
              this.dialogClosed()
              msgInfoEl({
                  type: 'success',
                  message: res.message
              })
              console.log('指派签署人成功')
          }).finally(() => {
              this.assignDisable = false
          })
        },
        // 上传附件按钮
        upload() {
            console.log('this.prjFileTypeOption', this.prjFileTypeOption)
            this.queryAssignOrg = {}
            if (this.prjFileTypeOption.length === 0) {
                this.isUploadBtn = true
                this.dialogUploadNew = true
                this.dialogTitle = '上传附件'
                this.assType = 'upload'
                this.dialogEl('dialogUploadNewRef')
            } else {
                msgInfoEl({
                    type: 'info',
                    message: '当前流程节点无可上传的附件信息，请联系维护人员增加上传需求'
                })
            }
        },

        // TODO RYC
        // 上传附件中-签署人改变事件
        changeSignatory(val1, val2) {
          console.log('eeeeeeeeeeeeeeeee')
            this.isShowStampUnit = val1
        },
        // 电子签章上传接口  逻辑修改，之前在上传中指定电子签章，目前可能用不到
        eleSignUpload(uploadForm) {
          console.log(uploadForm, 'eleSignUpload')
            if (!uploadForm.fileList.length) {
                return msgInfoEl({
                    type: 'info',
                    message: '请上传文件'
                })
            }
            if (this.isShowStampUnit && !this.assignUserId) {
                return msgInfoEl({
                    type: 'info',
                    message: '请选择签署人'
                })
            }
            const params = {
                file: uploadForm.fileList[0].raw, // 文件
                docFileType: uploadForm.docTypeCode, // 文件类型
                taskId: this.taskId, // 项目id
                isChange: '0', // 上传方式 0:正常上传的,1:整改的,2:继承的
                operateSystem: '0', // 操作系统，0:PMS,1:施工管理
                operateType: '1' // 操作类型，1:新增，2:补传
            }
            const formData = new FormData()
            Object.keys(params).forEach(key =>
                formData.append(key, params[key])
            )
            signUploadFileWithoutPrj(formData).then(res => {
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                if (this.isShowStampUnit) {
                  console.log(res, '上传返回结果')
                  const fileInfo = res.data?.data[0]
                  this.assignSignatory({
                      docId: fileInfo.file_id,
                      docName: fileInfo.file_name
                  }, res.data)
                } else {
                    this.dialogUploadNew = false
                    this.doSearch()
                    this.dialogClosed()
                    msgInfoEl({
                        type: 'success',
                        message: res.message
                    })
                }
            })
        },
        // 获取附件允许上传文件类型数据
        getPrjFileType() {
            const {
                prjType, // 项目类型
                nodeId, // 当前节点ID
                buildModes, // 建设模式
                towerType, // 塔类型
                roomType // 室分类型
            } = this.prjParams
            const params = {
                prjType, // 项目类型
                nodeId, // 当前节点ID
                buildModes, // 建设模式
                towerType, // 塔类型
                roomType // 室分类型
            }
            getPrjFileTypeApi(params).then(res => {
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                this.prjFileTypeOption = res.data
            })
        },
        // 选择项目
        async selectPrjFun(row) {
          console.log(row)
            this.dialogTitle = '选择项目'
            this.selectPrj = true
            this.isShowSelectPrj = true
        },
        submitPerson(userId, selectRow) {
          console.log(userId, '子调父')
          this.assignUserId = userId
          this.selectRow = selectRow
          this.accountType = this.selectRow?.orgType === 's' ? '2' : '1'
          this.organizeNo = this.selectRow?.orgCode
        },
        // 签字
       async confirmSign(row) {
          console.log(row, 'confirmSign')
          if (!this.tableData.length) {
            return this.$message('暂无可签署文件')
          }
          if(this.currentNode==='electronicSeal_103'){
            const paramsObj = {
              docIds: row.map(item => { return item.docId }),
              taskId: this.taskId,
            }
            const { code, data } = await writeSignature(paramsObj)
            if (+code === 200) {
              window.open(data, '_blank')
            }
            return
          }
          writeSignatureOld(row[0].docId).then(res => {
              if (+res.code !== 200) {
                return Promise.reject(res)
              }
              window.open(res.data, '_blank')
            })
        },
        // 上传电子签章指派附件
        assignSignatory(uploadForm) {
          const params = {
            taskId: this.taskId,
            docId: uploadForm.docId,
            docName: uploadForm.docName, // 项目id
            signers: [{
              accountType: this.accountType,
              uniqueId: this.assignUserId,
              signType: '0',
              organizeNo: this.organizeNo
            }],
            isCreateInstance: '1'
          }
          this.assignDisable = true
          assignFixedSignatory(params).then(res => {
            if (+res.code !== 200) {
                return Promise.reject(res)
            }
            this.dialogUploadNew = false
            this.doSearch()
            this.dialogClosed()
            msgInfoEl({
                type: 'success',
                message: res.message
            })
            console.log('指派签署人成功')
          }).finally(() => {
            this.assignDisable = false
          })
        },
        // 上传事件
        batchUploadClick() {
            const uploadForm = this.isUploadBtn ? this.$refs.uploadAttachRef.uploadForm : {}
            if (uploadForm.isEleSign === '0') {
                this.attachmentUpload(uploadForm)
            } else {
              this.eleSignUpload(uploadForm)
            }
        },
        // 附件上传
        attachmentUpload(uploadForm) {
            if (this.isUploadBtn && !uploadForm.fileList.length) {
                return msgInfoEl({
                    type: 'info',
                    message: '请上传文件'
                })
            }
            const params = {
                file: uploadForm.fileList[0].raw, // 文件
                docFileType: uploadForm.docTypeCode, // 文件类型
                taskId: this.taskId, // 项目id
                isChange: '0', // 上传方式 0:正常上传的,1:整改的,2:继承的
                operateSystem: '0', // 操作系统，0:PMS,1:施工管理
                operateType: '1' // 操作类型，1:新增，2:补传
            }
            const formData = new FormData()
            Object.keys(params).forEach(key =>
                formData.append(key, params[key])
            )
            signUploadFileWithoutPrj(formData).then(res => {
              if (+res.code !== 200) {
                  return Promise.reject(res)
                }
                this.dialogUploadNew = false
                this.doSearch()
                msgInfoEl({
                    type: 'success',
                    message: res.message
                })
            })
        }
    }
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
//   height:70%;
}
.search-flex-box {
    // display: flex;
    // justify-content: space-between;
    height: auto;
}
.searchBtn {
    width: 100px;
    margin-left: auto;
    display: flex;
    margin-top: 4px;
    flex-direction: column;
    .el-button + .el-button {
        margin-left: 0;
        margin-top: 8px;
    }
}

.electronicSignature {
    width: 100%;
    .mainDetails {
        //padding: 0 25px;
    }
    .topRemark {
        // background-color: #fdf5e6;
        background-color: #ffefd5;
        width: 100%;
        height: 40px;
        line-height: 40px;
        padding-left: 10px;
        font-size: 14px;

        .asterisk {
            color: #f00;
            margin-right: 2px;
            font-size: 18px;
        }
    }

    .customBtn {
        height: 20px;
        line-height: 20px;
        font-size: 14px;
        margin: 10px 20px 10px 90%;
        cursor: pointer;

        .el-icon-s-tools {
            font-size: 20px;
            color: #999;
            margin-right: 6px;
        }
    }
}

.el-button--text {
    color: #02A7F0;
}

.el-button--primary {
    color: #fff;
}
.dialog-footer {
    display: flex;
    justify-content: center;
}
::v-deep .el-button + .el-button {
    color: #fff;
}
// 弹框样式
::v-deep .el-dialog__body {
    overflow-y: auto;
}
// 滚动条样式
::v-deep .el-dialog__body::-webkit-scrollbar {
  // 滚动条整体样式
  width: 6px; //高宽分别对应横竖滚动条的尺寸
  height: 10px;
}
::v-deep .el-dialog__body::-webkit-scrollbar-thumb {
  // 滚动条里面小方块
  border-radius: 10px;
  // -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  background: #f2f3f5;
}
</style>
./attachSignInfo
